<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="../static/css/adminUpdate.css">
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
</head>

</head>


<body>
    <div class="row align-items-center">
        <div class="col"></div>
        <div class="col">
            <div class="alert alert-dark invisible" role="alert_fn">
                <strong>提示!</strong>
                <font id="msgId">错误！</font>
            </div>
        </div>

        <div class="col"></div>

    </div>
    <div class="htmleaf-container">
        <form action="" id="newRegisterForm">
            <div class="wrapper">

                <body translate="no">
                    <div class="login-box">
                        <h2>修改密码</h2>
                        <form class="form">
                            <!-- 
                            <div class="user-box">
                                <input type="password" name="passpassword" id="password" required="">
                                <label>旧的密码</label>
                            </div> -->
                            <div class="user-box">
                                <input type="password" name="password" id="password" required="">
                                <label>新的密码</label>
                            </div>

                            <div class="user-box">
                                <input type="password" name="repassword" id="repassword" required="">
                                <label>确认密码</label>
                            </div>
                            <a href="#" onclick="jump()">
                                <span></span>
                                <span></span>
                                <span></span>
                                <span></span>
                                确认修改
                            </a>
                            <a href="/admin" onclick="">
                                <span></span>
                                <span></span>
                                <span></span>
                                <span></span>
                                取消
                            </a>
                        </form>
                    </div>
            </div>
        </form>
    </div>


    <script src="../static/js/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <script src="../static/js/bootstrap.min.js"></script>
    <script>
        $('#login-button').click(function (event) {
            event.preventDefault();
            $('form').fadeOut(500);
            $('.wrapper').addClass('form-success');
        });
    </script>
    <script>
        function jump() {
            let pwd = $('#password').val();
            let confirmpwd = $('#repassword').val();

            if (pwd.length > 0 && pwd === confirmpwd) {
                axios({
                    method: 'post',
                    url: '/vimPwd',
                    data: $('#newRegisterForm').serialize(),
                }).then(function (res) {
                    res = res.data;
                    if (res.code === 200) {
                        window.location.href = '/admin';
                    } else {
                        alert_fn(res.msg);
                        console.log(res.msg);
                    }
                }).catch((err) => {
                    alert_fn(err);
                    console.log(err);
                });
            } else {
                alert_fn('密码不一致');
            }
        }

        function alert_fn(msg) {
            $('#msgId').text(msg);
            $('.alert').removeClass('invisible');
            setTimeout(() => {
                $('.alert').addClass('invisible');
            }, 3000);
        }
    </script>
</body>

</html>